<?php

namespace app\api\controller;

use app\api\model\OrderModel;
use think\Cache;
use think\Controller;
use app\api\service\Token;
require (EXTEND_PATH.'bdxcxpay/pay/rsasigndemo.php');

class Pay extends Controller
{
    //百度支付
    public function bd_pay()
    {
        $order_id = input('param.id');
        $uid = Token::getCurrentTokenVar('uid');
//        $uid = 129;
        $order = OrderModel::getOneOrder($order_id,$uid);
        $data=[];
        $data['dealId']=config('dealId');
        $data['appKey']=config('appKey');
//        $data['totalAmount']=$order['order_price'];
        $data['totalAmount']=$order['order_price']*100;
        $data['tpOrderId'] = $order['order_num'];
        $data['dealTitle']=$order['goods_name'];
        $rsa = new \rsasigndemo();
        $rsaInfo = $rsa->createRsa($order['order_num']);
        $data['signFieldsRange']=$rsaInfo['sign'];
        $data['rsaSign']=$rsaInfo['sign'];
        file_put_contents(RUNTIME_PATH.'/log/payrsa.txt',$data['rsaSign']);
//        $data['bizInfo']='{}';
        $data['bizInfo']=array('tpData'=>array(
                            'appKey'=>config('appKey'),
                            'dealId' => config('dealId'),
                            'tpOrderId' =>$data['tpOrderId'],
                            'totalAmount'=>$data['totalAmount'],
                            'rsaSign'=>$data['rsaSign'],
                            'displayData'=>array('cashierTopBlock'=>array(
                array(
                    array(
                        'leftCol'=>'订单名称',
                        'rightCol' =>$data['dealTitle']),
                    array(
                        'leftCol"'=>'数量',
                        'rightCol'=>'1'
                    ),
                    array(
                        'leftCol"'=>'订单金额',
                        'rightCol'=>'1'
                    )
                ),

            ))));
        $data['bizInfo']=json_encode($data['bizInfo']);
        return json(msg(1,$data,'预支付成功'));

    }

}
